package com.liu.resume;

import android.app.Activity;
import android.support.multidex.MultiDexApplication;

import com.liu.resume.model.UserModel;
import com.liu.resume.util.OfflineJsonMgr;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.update.BmobUpdateAgent;

/**
 * Created by Administrator on 2016/9/24.
 */
public class MyApplication extends MultiDexApplication {
    public static MyApplication INSTANCE;
    public boolean isLogin = false;
    private UserModel userModel;
    private List<Activity> mActivities = new ArrayList<Activity>();
    @Override
    public void onCreate() {
        super.onCreate();
        INSTANCE = this;
        initBase();
//        MyCrashHandler.getInstance().init(this);
        //初始化
        Bmob.initialize(this,getString(R.string.appid_bmob));
        BmobUpdateAgent.initAppVersion();
    }

    public void initBase() {
        //读取用户登陆内容
        Object object = OfflineJsonMgr.getInstance(this).getJsonObject(UserModel.class);
        if (object != null) {
            userModel = (UserModel) object;
            if (userModel != null) {
                isLogin = true;
            }
        }
    }

    public void setUserInfo(UserModel userModel) {
        this.userModel = userModel;
        isLogin = (userModel != null);
    }

    public UserModel getUserInfo() {
        return userModel;
    }
    public void addActivity(Activity activity) {
        mActivities.add(activity);
    }

    public void removeActivity(Activity activity) {
        mActivities.remove(activity);
    }

    public void exit() {
        for (Activity activity : mActivities) {
            if (!activity.isFinishing())
                activity.finish();
        }
    }

}
